import request from '@/utils/request'
import { cached_data } from '@/utils/cache'

const api = 'partyGroup/'
const urlGetGroup = `${api}/companyGroup`
export function getList({ company }) {
  return new Promise((res, rej) => {
    cached_data(`${urlGetGroup}`, () =>
      request.get(urlGetGroup, {
        params: {
          code: company
        }
      })
    ).then(data => {
      data.list.map(i => {
        i.name = i.alias
      })
      res(data.list)
    }).catch(e => rej(e))
  })
}

/**
 * 党组织成员
 *
 * @export
 * @param {*} { company, groupid, page }
 * @return {*}
 */
export function members({ company, groupid, page }) {
  return request.get(`${api}/members`,
    {
      params: Object.assign({ company, groupid }, page)
    })
}

/**
 * 获取成员类别统计
 *
 * @export
 * @param {*} { company, groupid }
 * @return {*}
 */
export function memberStatistics({ company, groupid }) {
  return request.get(`${api}/memberStatistics`, {
    params: { company, groupid }
  })
}
export default {
  getList,
  members,
  memberStatistics
}
